<?php

class dbhelper {

    private $query = "";
    private $conn;

    function db_helper() {

    }

    public function open() {

        include("dbconfig.php");

        $this->conn = mysql_connect($dbserver, $dbuser, $dbpass) or die
                        ('Error connecting to mysql');
        mysql_query("SET character_set_results=utf8", $this->conn);
        mysql_set_charset('utf8',$this->conn); 
        mysql_select_db($dbname) or die
                        ('Error to select database ' . $dbname);
        
    }

    public function close() {

        mysql_close($this->conn);
    }

    public function excuteQuery(&$query) {
        $this->open();
        $result = mysql_query($query);
        $this->close();

        return $result;
    }

    public function setQuery($query) {
        $this->query = $query;
    }

    public function set_string_params($param_name, $param_value) {

        $this->query = str_replace('#' . $param_name."#", "'" . $param_value . "'", $this->query);
        
    }

    public function set_int_params($param_name, $param_value) {
        $this->query = str_replace('#' . $param_name."#", $param_value, $this->query);
        //echo $this->query;
        
    }

    public  function excute() {
        $this->open();        
        $result = mysql_query($this->query);
        $this->close();
        return $result;
    }

}
?>

